﻿#pragma once
#include"RBTree.h"

namespace MyMap
{
	template<class K, class V>
	class Map
	{
	public:
		struct KOfV
		{
		public:
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};

		typedef typename RB::RBTree<pair<const K, V>, KOfV>::iterator iterator;

		iterator begin()
		{
			return _t.Begin();
		}

		iterator end()
		{
			return _t.End();
		}

		bool insert(const pair<K, V>& kv)
		{
			return (_t.Insert(kv)).second;
		}

	private:
		RB::RBTree<pair<const K, V>, KOfV> _t;
	};

	void test_map()
	{
		Map<string, int> m;
		m.insert({ "a",1 });
		m.insert({ "b",1 });
		m.insert({ "c",1 });
		m.insert({ "d",3 });

		Map<string, int>::iterator it = m.begin();
		while (it != m.end())
		{
			//it->first += 'x';
			it->second += 1;

			//cout << it.operator->()->first << ":" << it->second << endl;
			cout << it->first << ":" << it->second << endl;
			it++;
		}
		cout << endl;
	}
}